package exa.unicen.edu.ringo.raccess.resources;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import exa.unicen.edu.ringo.raccess.model.manager.ConfigurationManager;
import exa.unicen.edu.ringo.rmodel.bean.Configuration;
import exa.unicen.edu.ringo.rmodel.builder.ModelBuilder;

@Path("/configuration")
public class ConfigurationResource {

	private ModelBuilder builder = ModelBuilder.instance;
	private ConfigurationManager manager = ConfigurationManager.instance;
	
	@POST
	@Consumes({"application/xml","text/xml"})
	@Produces({"application/xml","text/xml"})
	public String  set(String xml) {
		Configuration configuration = (Configuration) builder.marshal(Configuration.class, xml);
		
		manager.set(configuration);
		
		return xml;
	}	
	
	@GET
	@Produces({"application/xml","text/xml"})
	public String get() {
		
		Configuration configuration = manager.get();

		return builder.unmarshal(Configuration.class, configuration);
	}
	

}
